package com.iursp.service.user;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iursp.conf.aop.LoggerManage;
import com.iursp.domain.model.UihPage;
import com.iursp.domain.model.role.Role;
import com.iursp.domain.model.user.User;
import com.iursp.mapper.user.UserMapper;
import com.iursp.utils.common.LogUtils;

import javassist.NotFoundException;

@Service
public class UserService {
	
	@Autowired
	private UserMapper userMapper;

	public PageInfo<User> queryAllUsers(User user) {
		return PageHelper.startPage(1, 10).doSelectPageInfo(() -> userMapper.selectAll());
	}

	public int delUserById(String id) {
		return userMapper.delUserById(id);
	}
	@LoggerManage(logStr = "用户管理-->根据角色获取用户")
	public UihPage<User> getRoleUserListPage(Role role, Integer limit, Integer offset) {
		try {
			PageHelper.startPage(offset, limit);
			List<User> list = userMapper.getRoleUserList(role);
			LogUtils.get().setLog("角色获取成功,失败原因-->业务层逻辑");
			return new UihPage<>(list.size(), list);
		} catch (Exception e) {
			try {
				LogUtils.get().setLog("角色获取用户,失败原因-->"+e.toString());
			} catch (NotFoundException e1) {
				e1.printStackTrace();
			}
			return null;
		}
		
	}
	
}
